package com.example.spring_xx_u_market;

import com.example.bean.ErrorCodeV;
import com.example.bean.GoodsBrowsV;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import util.UidCtrl;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping("api")
public class GoodsVCtrl {
    @PostMapping("goods")
    public Object getGoods(HttpServletRequest request) {
        int size = 20, goods_number = 0;
        String uid = request.getParameter("uid");
        String sizeStr = request.getParameter("size");
        String goods_numberStr = request.getParameter("goods_number");

        if (uid == null ) {
            return new ErrorCodeV("005");
        } else {
            if (goods_numberStr!=null&&sizeStr!=null){
                goods_number = Integer.parseInt(goods_numberStr);
                size = Integer.parseInt(sizeStr);
            }

            switch (UidCtrl.checkUid(uid)) {
                case "-2":
                    return new ErrorCodeV("003");
                case "-1":
                    return new ErrorCodeV("002");
                case "0":
                    return new ErrorCodeV("004");
                default:
                    return new GoodsBrowsV(size, goods_number);
            }
        }

    }
}
